package com.mz361.modules.system.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mz361.common.enums.StatusEnum;
import com.mz361.common.utils.StatusUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author niceale
 * @date 2023/10/24
 */
@Data
@Entity
@Table(name = "std_payOrder")
@EntityListeners(AuditingEntityListener.class)
@Where(clause = StatusUtil.NOT_DELETE)
public class PayOrder implements Serializable {
    // 主键ID
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    // OPENID
    private String openid;
    // 订单ID
    private String orderId;
    // 订单类型 1：产品订单；2：套餐订单
    private String orderType;
    //退款单号
    private String refundId;
    // 支付系统生成的订单号
    private String transactionId;
    // 支付系统生成的退款单号
    private String payRefundId;
    /* 交易类型，枚举值：
    JSAPI：公众号支付
    NATIVE：扫码支付
    App：App支付
    MICROPAY：付款码支付
    MWEB：H5支付
    FACEPAY：刷脸支付*/
    private String tradeType;
    /**
     * 支付方式：WeChat Alipay
     */
    private String payType;
    // 套餐标识
    private String paidPackageTag;
    // 邀请码 用于统计销售人员订单数据用
    private String inviteCode;
    // SOURCEKEY
    private String sourceKey;
    // 客户ID
    private Long memeberId;
    @ManyToOne
    @JoinColumn(insertable = false, updatable = false, name = "memeberId", referencedColumnName = "id")
    @JsonIgnore
    @NotFound(action = NotFoundAction.IGNORE)
    private CMember cMember;
    // 企业ID
    private Long companyId;
    // 企业名称
    private String companyName;
    @ManyToOne
    @JoinColumn(insertable = false, updatable = false, name = "companyId", referencedColumnName = "id")
    @JsonIgnore
    @NotFound(action = NotFoundAction.IGNORE)
    private Company company;
    // 素材名称
    private String tag;
    // 购买价格（分）
    private Long price;
    // 支付金额 (分)
    private Long totalFee;

    /*支付状态
    交易状态，枚举值：
    SUCCESS：支付成功
    REFUND：转入退款
    NOTPAY：未支付
    CLOSED：已关闭
    REVOKED：已撤销（付款码支付）
    USERPAYING：用户支付中（付款码支付）
    PAYERROR：支付失败(其他原因，如银行返回失败)*/
    private String resultStatus;
    // 支付结果返回
    private String resultCode;
    // 发票状态
    @ApiModelProperty(notes = "发票状态")
    private String invoiceStatus;
    // 支付回调信息返回码
    private String returnCode;
    //  返回信息
    private String returnData;
    // 创建时间
    @CreatedDate
    private Date createDate;
    // 更新时间
    @LastModifiedDate
    private Date updateDate;
    // 创建者
    @CreatedBy
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "create_by")
    @JsonIgnore
    private User createBy;
    // 更新者
    @LastModifiedBy
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "update_by")
    @JsonIgnore
    private User updateBy;
    // 数据状态
    private Byte status = StatusEnum.OK.getCode();
}